package cn.hl.hm.util;

import java.util.List;

import javax.servlet.http.Cookie;

public class Tools {

    public static boolean isEmpty(String val) {
        if (val == null || val.trim().equals("")) {
            return true;
        } else {
            return false;
        }
    }

    @SuppressWarnings("rawtypes")
    public static boolean isEmptyList(List list) {
        if (list == null || list.size() < 1) {
            return true;
        } else {
            return false;
        }
    }

    public static String getCookieValue(Cookie[] cookies, String key) {
        if (cookies == null || cookies.length < 1) {
            return null;
        }
        for (Cookie cookie : cookies) {
            if (key.equals(cookie.getName())) {
                return cookie.getValue();
            }
        }
        return null;
    }

    public static String generateInStr(Object[] vals) {
        if (vals == null) {
            return null;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < vals.length; i++) {
            if (i > 0) {
                sb.append(",");
            }
            sb.append("?");
        }
        return sb.toString();
    }

    public static String generateInValue(Object[] vals) {
        if (vals == null) {
            return null;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < vals.length; i++) {
            if (i > 0) {
                sb.append(",");
            }
            sb.append(vals[i].toString());
        }
        return sb.toString();
    }
    public static boolean isNotBank(String val) {
    	if(val !=null && !("null".equals(val)) && val !="" && !("".equals(val))){
    		return true;
    	}
        else {
            return false;
        }
    }
    public static boolean isBank(String val) {
    	if(null ==val || ""==val || "null".equals(val) || "".equals(val)){
    		return true;
    	}
    	
        else {
            return false;
        }
    }
    public static boolean isNotInteger(Integer val) {
    	if(val !=null && !("null".equals(val)) && val > 0){
    		return true;
    	}
        else {
            return false;
        }
    }
    public static boolean isInteger(Integer val) {
    	if(null == val || "null".equals(val) || val <1){
    		return true;
    	}
        else {
            return false;
        }
    }
    public static boolean isNotObject(Object val) {
    	if(val !=null && !("null".equals(val)) && !("".equals(val)) && val !=""){
    		return true;
    	}
        else {
            return false;
        }
    }
    public static boolean isObject(Object val) {
    	if("" == val || null == val || "null".equals(val) || "".equals(val)){
    		return true;
    	}
    	
        else {
            return false;
        }
    }
}
